#include "StdAfx.h"

SWEGL_DXWRAPPER_IMPLEMENT_IUNKNOWN(myIDirect3DSurface9, IDirect3DSurface9);

myIDirect3DSurface9::myIDirect3DSurface9(Surface *surface) : m_surface(surface)
{
	SWEGL_DXWRAPPER_INIT_IUNKNOWN();
}

myIDirect3DSurface9::~myIDirect3DSurface9()
{
}

HRESULT myIDirect3DSurface9::GetDevice(IDirect3DDevice9** ppDevice)
{
    SWEGL_DXWRAPPER_NYI(); return E_NOTIMPL;
}

HRESULT myIDirect3DSurface9::SetPrivateData(REFGUID refguid,CONST void* pData,DWORD SizeOfData,DWORD Flags)
{
    SWEGL_DXWRAPPER_NYI(); return E_NOTIMPL;
}

HRESULT myIDirect3DSurface9::GetPrivateData(REFGUID refguid,void* pData,DWORD* pSizeOfData)
{
    SWEGL_DXWRAPPER_NYI(); return E_NOTIMPL;
}

HRESULT myIDirect3DSurface9::FreePrivateData(REFGUID refguid)
{
    SWEGL_DXWRAPPER_NYI(); return E_NOTIMPL;
}

DWORD myIDirect3DSurface9::SetPriority(DWORD PriorityNew)
{
    sweglInfo("%s: NYI\n", SWEGL_FUNCTION); return 0;
}

DWORD myIDirect3DSurface9::GetPriority()
{
    sweglInfo("%s: NYI\n", SWEGL_FUNCTION); return 0;
}

void myIDirect3DSurface9::PreLoad()
{
	sweglInfo("%s: NYI\n", SWEGL_FUNCTION);
}

D3DRESOURCETYPE myIDirect3DSurface9::GetType()
{
	return D3DRTYPE_TEXTURE;
}

HRESULT myIDirect3DSurface9::GetContainer(REFIID riid, void** ppContainer)
{
	sweglInfo("%s: NYI\n", SWEGL_FUNCTION);
    return E_NOTIMPL;
}

HRESULT myIDirect3DSurface9::GetDesc(D3DSURFACE_DESC *pDesc)
{
	sweglInfo("%s: %p\n", SWEGL_FUNCTION, this);
	sweglInfo("%s: %p\n", SWEGL_FUNCTION, m_surface);
	pDesc->Format = D3DFMT_X8R8G8B8;
	pDesc->Type = D3DRTYPE_SURFACE;
	pDesc->Usage = 0;
	pDesc->Pool = D3DPOOL_DEFAULT;
	pDesc->MultiSampleType =  D3DMULTISAMPLE_NONE;
	pDesc->MultiSampleQuality = 0;
	pDesc->Width = m_surface->width();
	pDesc->Height = m_surface->height();
	return S_OK;

}

HRESULT myIDirect3DSurface9::LockRect(D3DLOCKED_RECT* pLockedRect,CONST RECT* pRect,DWORD Flags)
{
	if (pRect)
		sweglInfo("%s: %d->%d %d->%d\n", SWEGL_FUNCTION, pRect->left, pRect->right, pRect->top, pRect->bottom);
	else
		sweglInfo("%s: all\n", SWEGL_FUNCTION);
	pLockedRect->pBits = m_surface->data();
	pLockedRect->Pitch = m_surface->width() * sizeof(uint32);
    return S_OK;
}

HRESULT myIDirect3DSurface9::UnlockRect()
{
	sweglInfo("%s\n", SWEGL_FUNCTION);
    return S_OK;
}

HRESULT myIDirect3DSurface9::GetDC(HDC *phdc)
{
	sweglInfo("%s: NYI\n", SWEGL_FUNCTION);
    return E_NOTIMPL;
}

HRESULT myIDirect3DSurface9::ReleaseDC(HDC hdc)
{
	sweglInfo("%s: NYI\n", SWEGL_FUNCTION);
    return E_NOTIMPL;
}
